//
//  FindViewController.m
//  A_HandHeldLOL
//
//  Created by Zhao YanBin on 16/1/16.
//  Copyright © 2016年 zhaoyanbin. All rights reserved.
//

#import "FindViewController.h"
#import "AFNModel.h"
#import "TeamCollectionViewCell.h"
#import "TeamModel.h"
#import "TeamTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "DetailsViewController.h"
#import "BizhiViewController.h"
#import "PaiHangbangViewController.h"
#import "ZhaohuanshiViewController.h"
#import "WupinViewController.h"
@interface FindViewController ()<UICollectionViewDataSource, UICollectionViewDelegate,UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UICollectionView *collection;
@property(nonatomic, retain)NSMutableArray *collectionArr;

//tableview
@property(nonatomic, retain)UITableView *tableView;
//头部自定义
@property(nonatomic, retain)UIView *header;
@property(nonatomic, retain)NSArray *arr;

//4个label
@property(nonatomic, retain)UILabel *wupin;
@property(nonatomic, retain)UILabel *jineng;
@property(nonatomic, retain)UILabel *paihang;
@property(nonatomic, retain)UILabel *bizhi;
//4个BUTTON
@property(nonatomic, retain)UIButton *wupinbtn;
@property(nonatomic, retain)UIButton *jinengbtn;
@property(nonatomic, retain)UIButton *paihangbtn;
@property(nonatomic, retain)UIButton *bizhibtn;
@end

@implementation FindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"发现";
//    self.navigationController.navigationBar.translucent = NO;

    //创建collection
    [self creacollectionView];
    
    
    //collection数据处理
    [self collectiondata];
    
    [self button];
    //tableView创建
//    [self creatableview];
}
//-(void)creatableview
//{
//    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
//    _tableView.delegate = self;
//    _tableView.dataSource = self;
//    _tableView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:_tableView];
//    
//    
//    //注册重用池
//    [self.tableView registerClass:[UITableView class] forCellReuseIdentifier:@"cell1"];
//    self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 300)];
//    _tableView.tableHeaderView = _header;
//    [_tableView release];
//    
//    [self data];
//}
//
////数据处理
//-(void)data
//{
//    self.arr = @[@"游戏资料",@"社区",@"壁纸"];
//    
//}
////两个tableView方法
//-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    return _arr.count;
//}
//
//-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
//    return cell;
//    
//}


//4个下方按钮
-(void)button
{
    self.wupinbtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.wupinbtn.frame = CGRectMake(50, 300, 100, 100);
    _wupinbtn.backgroundColor = [UIColor redColor];
    [_wupinbtn setBackgroundImage:[UIImage imageNamed:@"zhuangbei"] forState:UIControlStateNormal];
    [_wupinbtn addTarget:self action:@selector(wupin:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_wupinbtn];
    self.wupin = [[UILabel alloc] initWithFrame:CGRectMake(50, 400, 100, 50)];
//    _a1.backgroundColor = [UIColor greenColor];
    _wupin.text = @"物品";
    _wupin.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_wupin];
    [_wupin release];
    
    
    self.jinengbtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.jinengbtn.frame = CGRectMake(225, 300, 100, 100);
    _jinengbtn.backgroundColor = [UIColor yellowColor];
    [_jinengbtn setBackgroundImage:[UIImage imageNamed:@"zhaohuanshi"] forState:UIControlStateNormal];
    [_jinengbtn addTarget:self action:@selector(jineng:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_jinengbtn];
    self.jineng = [[UILabel alloc] initWithFrame:CGRectMake(225, 400, 100, 50)];
//    _a2.backgroundColor = [UIColor greenColor];
    _jineng.text = @"召唤师技能";
    _jineng.textAlignment = NSTextAlignmentCenter;

    [self.view addSubview:_jineng];
    [_jineng release];
    
    self.paihangbtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.paihangbtn.frame = CGRectMake(50, 450, 100, 100);
    _paihangbtn.backgroundColor = [UIColor redColor];
    [_paihangbtn setBackgroundImage:[UIImage imageNamed:@"paihangbang"] forState:UIControlStateNormal];
    [_paihangbtn addTarget:self action:@selector(paihangbang:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_paihangbtn];
    self.paihang = [[UILabel alloc] initWithFrame:CGRectMake(50, 550, 100, 50)];
//    _a3.backgroundColor = [UIColor greenColor];
    _paihang.text = @"国服排行榜";
    _paihang.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_paihang];
    [_paihang release];
    
    self.bizhibtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.bizhibtn.frame = CGRectMake(225, 450, 100, 100);
    _bizhibtn.backgroundColor = [UIColor redColor];
    [_bizhibtn setBackgroundImage:[UIImage imageNamed:@"bizhi"] forState:UIControlStateNormal];
    [_bizhibtn addTarget:self action:@selector(bizhi:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_bizhibtn];
    self.bizhi = [[UILabel alloc] initWithFrame:CGRectMake(225, 550, 100, 50)];
//    _a4.backgroundColor = [UIColor greenColor];
    _bizhi.text = @"精选壁纸";
    _bizhi.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_bizhi];
    [_bizhi release];
}

//召唤师技能点击
-(void)jineng:(UIButton *)btn
{
    ZhaohuanshiViewController *zhsVC = [[ZhaohuanshiViewController alloc] init];
    [self.navigationController pushViewController:zhsVC animated:YES];
}
//排行榜点击
-(void)paihangbang:(UIButton *)btn
{
    PaiHangbangViewController *phbVC = [[PaiHangbangViewController alloc] init];
    [self.navigationController pushViewController:phbVC animated:YES];
}

//壁纸点击
-(void)bizhi:(UIButton *)btn
{
    BizhiViewController *bzVC = [[BizhiViewController alloc] init];
    [self.navigationController pushViewController:bzVC animated:YES];
}

//物品点击
-(void)wupin:(UIButton *)btn
{
    WupinViewController *wpVC = [[WupinViewController alloc] init];
    [self.navigationController pushViewController:wpVC animated:YES];
}

//上方滚动条
-(void)creacollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake((375 - 20) / 5, 100);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 64, 10);
//    [layout release];
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width , 200) collectionViewLayout:layout];
//    _collection.backgroundColor = [UIColor whiteColor];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.tag = 2000;
    [self.view addSubview:_collection];
    [_collection release];
//    [layout release];
    
    //隐藏滚动条
//    _collection.showsHorizontalScrollIndicator = NO;
    
    //注册
    [_collection registerClass:[TeamCollectionViewCell class ] forCellWithReuseIdentifier:@"cell"];
    
}
//collection数据处理
-(void)collectiondata
{
    NSString *collectionstr = @"http://qt.qq.com/php_cgi/lol_mobile/club/varcache_team_entrancev2.php?version=$@&plat=ios";
    [AFNModel GETWithURL:collectionstr completion:^(id result) {
        NSArray *arr = result[@"clubs"];
//        NSLog(@"%@",arr);
        self.collectionArr = [TeamModel modelHanderWithArray:arr];
        [_collection reloadData];
    }];
    
    
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _collectionArr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TeamCollectionViewCell *collCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    TeamModel *m =  _collectionArr[indexPath.item];
    collCell.name.text = m.name;
    [collCell.tu sd_setImageWithURL:[NSURL URLWithString:m.iconUrl]];
//    collCell.backgroundColor = [UIColor yellowColor];
    return collCell;
}

//collection点击
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DetailsViewController *deVC = [[DetailsViewController alloc] init];
    deVC.detailsid = [_collectionArr[indexPath.item] Id];
    [self.navigationController pushViewController:deVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
